package com.kitty.util;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class LoginInterceptor extends AbstractInterceptor {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1041614186436997705L;
	public static final String USER_SESSION_KEY = "kitty.session.user";
	
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext actionContext = invocation.getInvocationContext();
		Map<String, Object> session = actionContext.getSession();
		
		if (session != null && session.get(USER_SESSION_KEY) != null) {
			return invocation.invoke();
		} else {
			return "login";
		}
	}
}
